<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ToolController extends Controller
{
    public function uploadImage(Request $request){
        $fn = $request->filled('filename')
        if($request->hasFile('upload_logo') && $request->file('upload_logo')->isValid()){
            $img_url = QclouduUpload(md5(uniqid(md5(microtime(true)),true).uniqid().Config('app')['name']), $request->file('upload_logo')->getRealPath());
            return json_encode([
                'code' => 1,
                'msg' => 'success',
                'img_url' => $img_url
            ]);
        }else{
            return json_encode([
                'code' => 0,
                'msg' => '图片上传出错，请联系管理员'
            ]);
        }
    }

    public function randomKey($length){
        $pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';
        $key = '';
        for($i=0;$i<$length;$i++)
        {
            $key .= $pattern{mt_rand(0,61)};    //生成php随机数
        }
        return $key;
    }
}
